package com.chiao.action.admin;

import com.chiao.entity.admin.Employee;
import com.chiao.service.admin.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.chiao.service.admin.LoginService;
import javax.servlet.http.HttpSession;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;

@Controller
@RequestMapping(value="/admin")
public class AdminLogin {

	@Autowired
	LoginService service;
        
        @Autowired EmployeeService empService;
	
	@RequestMapping
	public String login(){
//		service.getdds();
//		service.updateXX();
//		service.add();
		return "admin/login";
	}
	
	@RequestMapping(value="/login")
        public String success(HttpSession session){
            UserDetails user = (UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
            Employee emp= empService.queryEmpByEmpno(user.getUsername());
            session.setAttribute("emp", emp);
            return "admin/index";
        }
}
